{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>

    <form class="layui-form layui-form-pane" lay-filter="form">

        <div class="layui-form-item">
            <label class="layui-form-label">假期名称</label>
            <div class="layui-input-4">
                <input type="text" name="name" id="name" lay-verify="required" placeholder="{:lang('pleaseEnter')}假期名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年份</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="year" id="year" placeholder="yyyy">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="start_time" id="start_time" placeholder="yyyy-MM-dd">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
                <input type="text"  class="layui-input" name="end_time" id="end_time" placeholder="yyyy-MM-dd">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('holiday')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>

</div>
{include file="common/foot"/}

<script>

    layui.use(['form','laydate', 'layer','upload'], function () {
        var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload,laydate = layui.laydate;
        var info = {$info|raw};
        form.val("form", info);
        form.render();

        // 监听提交按钮
        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var start_time    = $('#start_time').val();
            var end_time      = $('#end_time').val();

            if(start_time!=''&&end_time!=''&&(start_time<=end_time)){
                $.post("",data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            }else{
                layer.alert('假期时间有误');
                layer.close(loading);
                return false;
            }


        });
        laydate.render({
            elem: '#end_time'
            ,format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#start_time'
            ,format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#year'
            ,type: 'year'
        });

    });


</script>